package org.lql.chaos.core.exception.customize;

/**
 * @author: liangqinglong
 * @date: 2025-07-14 15:28
 * @description:
 **/
public class CustomizeExample {

	/**
	 * 1、自定义异常（受检查异常、编译时异常）
	 *
	 * @throws CustomizeException 自定义异常
	 */
	public static void fa() throws CustomizeException {
		throw new CustomizeException(ErrorCode.CUSTOMIZE_EXCEPTION);
	}

	/**
	 * 2、自定义运行时异常（非受检查异常、运行时异常）
	 *
	 * @throws CustomizeRuntimeException 自定义运行时异常
	 */
	public static void fb() throws CustomizeRuntimeException {
		throw new CustomizeRuntimeException(ErrorCode.CUSTOMIZE_RUNTIME_EXCEPTION);
	}

	/**
	 * 3、自定义运行时异常（非受检查异常、运行时异常）不主动抛出异常
	 */
	public static void fc() {
		throw new CustomizeRuntimeException(ErrorCode.CUSTOMIZE_RUNTIME_EXCEPTION);
	}

	/**
	 * 4、自定义错误（Error）
	 *
	 * @throws CustomizeError 自定义错误
	 */
	public static void fd() throws CustomizeError {
		throw new CustomizeError(ErrorCode.CUSTOMIZE_ERROR);
	}

	public static void main(String[] args) {

		try {
			fa();
		} catch (CustomizeException e) {
			e.printStackTrace();
		}

		try {
			fb();
		} catch (CustomizeRuntimeException e) {
			e.printStackTrace();
		}

		try {
			fc();
		} catch (CustomizeRuntimeException e) {
			e.printStackTrace();
		}

		try {
			fd();
		} catch (CustomizeError e) {
			e.printStackTrace();
		}

	}
}
